import { Controller, Get, Post, Body, Patch, Param, Delete, UseInterceptors, ClassSerializerInterceptor, Req, UseGuards } from '@nestjs/common';
import { AuthService } from './auth.service';
import { LoginAccountDto } from './dto/login-account.dto';
import { LoginEmailDto } from './dto/login-email.dto';
import type { Request } from 'express';
import { Public } from '@/common/decorators/public.decorator';
import { JwtRefreshGuard } from '@/common/guards/jwt-refresh.guard';
import { GetCurrentUserID } from '@/common/decorators/get-current-user-id.decorator';

@Controller()
export class AuthController {
  constructor(private readonly authService: AuthService) { }

  @Public()
  @Post('/login')
  @UseInterceptors(ClassSerializerInterceptor)
  login(@Body() loginAccountDto: LoginAccountDto | LoginEmailDto, @Req() req: Request) {
    return this.authService.login(loginAccountDto, req)
  }


  @Public()
  @Post('/refreshToken')
  @UseGuards(JwtRefreshGuard)
  refreshToken(@GetCurrentUserID() id: string) {
    return this.authService.refreshToken(+id)
  }


  @Get('/logout')
  async logout(@Req() req: Request) {
    return await this.authService.logout(req)
  }


}
